#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 1e5 + 10;
vector<LL> hui;
int a[N];
LL f[2][1 << 15];

bool check(LL k) {
  string a = to_string(k);
  string b = a;
  reverse(a.begin(), a.end());
  return a == b;
}
void dfs(int step, LL s) {
  if (step >= 15) {
    if (check(s)) {
      hui.push_back(s);
    }
    return;
  }
  dfs(step + 1, s + (1 << step));
  dfs(step + 1, s);
}

LL work() {

  memset(f, 0, sizeof(f));

  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  f[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (LL S = 0; S < (1 << 15); S++) {
      if (f[(i - 1) & 1][S] == 0)
        continue;
      f[i & 1][S] += f[(i - 1) & 1][S];
      f[i & 1][S ^ a[i]] += f[(i - 1) & 1][S]  ;
      cout << (S ^ a[i]) << "(" << f[i & 1][S ^ a[i]] << ")" << " ";
    }
    cout << endl;
  }
  LL ans = 0;
  for (auto x : hui) {
    cout << f[n & 1][x] << " ";
    if (f[n & 1][x] == -1)
      continue;
    ans += f[n & 1][x];
  }
  return ans;
}
int main() {
  dfs(0, 0);
  sort(hui.begin(), hui.end());
  /* for (auto x : hui) {
    cout << x << " ";
  } */
  int t;
  cin >> t;
  while (t--) {
    cout << work() << endl;
  }
  return 0;
}

/*   for (int k = 0; k <= 15; k++) {
        if ((a[i] >> k) & 1 == 1) */